package edu.kjxy.day02.suspend_resume_test;

/**
 * 功能:暂停线程,意味着线程还可以恢复。
 * 可以用suspend方法暂停线程，使用resume方法恢复线程的执行
 * 作者:程序员欧阳子韩
 * 日期:2024/2/1 12:13
 */
public class RunTest {
    public static void main(String[] args) {
        try {
            MyThread thread = new MyThread();
            thread.start();
            Thread.sleep(5000);
            //A段
            thread.suspend();
            System.out.println("A=" + System.currentTimeMillis() + "i=" + thread.getI());
            Thread.sleep(5000);
            System.out.println("A=" + System.currentTimeMillis() + "i=" + thread.getI());
            //B段
            thread.resume();
            Thread.sleep(5000);
            //C段
            thread.suspend();
            System.out.println("B=" + System.currentTimeMillis() + "i=" + thread.getI());
            Thread.sleep(5000);
            System.out.println("B=" + System.currentTimeMillis() + "i=" + thread.getI());
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
